﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.BLL
{
    public sealed class MasNamePrefixBLL : IMasNamePrefixBLL
    {
        private static readonly IMasNamePrefixDAL DAL = DataAccess.CreateMasterNamePrefixes();
        private static readonly IMasGenderDAL gdDAL = DataAccess.CreateMasterGender();

        private MasNamePrefixInfo npInfo = new MasNamePrefixInfo();
        public IList<MasNamePrefixInfo> ListNamePrefixes()
        {
            return DAL.ListNamePrefixes(new MasNamePrefixInfo(0));
        }
        public IList<MasNamePrefixInfo> ListNamePrefixes(string searchText)
        {
            return DAL.ListNamePrefixes(searchText);
        }
        public IList<MasNamePrefixInfo> ListNamePrefixesBySequence(string Sequence)
        {
            int seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            return DAL.ListNamePrefixes(new MasNamePrefixInfo(seq));
        }
        public IList<MasNamePrefixInfo> ListNamePrefixesByGender(string Genders)
        {
            MasGenderInfo genderInfo = new MasGenderInfo();
            genderInfo.Sequence = Genders.Length > 0 ? Int32.Parse(Genders) : 0;

            //IList<MasGenderInfo> genderList = gdDAL.ListMasGenders(genderInfo); //genderDAL.ListMasGenders(new MasGenderInfo((rdr.IsDBNull(5)) ? 0 : rdr.GetInt32(5)));
            //if (genderList.Count > 0)
            //    genderInfo = genderList[0];

            return DAL.ListNamePrefixes(new MasNamePrefixInfo(0, "", "", "", "", genderInfo, null, null));
            //MasGenderInfo genderInfo = new MasGenderInfo();

            //genderInfo.Sequence = Genders.Length > 0 ? Int32.Parse(Genders) : 0;
            //return DAL.ListNamePrefixes(new MasNamePrefixInfo(0, "", "", "", "", genderInfo, null, null));
        }
        public DataSet LoadNamePrefixes(Nullable<int> Sequence, Nullable<int> Gender)
        {
            int seq = Sequence.HasValue ?(int)Sequence : 0;
            MasGenderInfo genderInfo = new MasGenderInfo();
            genderInfo.Sequence = Gender.HasValue ? (int)Gender : 0;

            npInfo.Sequence = seq;
            npInfo.Genders = genderInfo;
            return DAL.LoadNamePrefixes(npInfo);
        }
        public DataSet LoadNamePrefixesENG(Nullable<int> Sequence, Nullable<int> Gender)
        {
            int seq = Sequence.HasValue ? (int)Sequence : 0;
            MasGenderInfo genderInfo = new MasGenderInfo();
            genderInfo.Sequence = Gender.HasValue ? (int)Gender : 0;

            npInfo.Sequence = seq;
            npInfo.Genders = genderInfo;
            return DAL.LoadNamePrefixesENG(npInfo);
        }
        public void Insert(string Name, string NameShort, string NameEng, string NameEngShort
            , Nullable<int> Genders, int CreatedBy)
        {
            try
            {
                MasGenderInfo genderInfo = new MasGenderInfo();
                if (Genders.HasValue)
                    genderInfo.Sequence = (int)Genders;

                DAL.Insert(new MasNamePrefixInfo(0, Name, NameShort, NameEng, NameEngShort, genderInfo, CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Name, string NameShort, string NameEng, string NameEngShort
            , Nullable<int> Genders, int UpdatedBy)
        {
            try
            {
                MasGenderInfo genderInfo = new MasGenderInfo();
                if (Genders.HasValue)
                    genderInfo.Sequence = (int) Genders;

                DAL.Update(new MasNamePrefixInfo(Sequence, Name, NameShort, NameEng, NameEngShort, genderInfo, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
